package com.cb.web.wasf.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.tagext.TryCatchFinally;

/**
 * @author CBO
 */
public class InsertFramentTag extends TagSupport implements TryCatchFinally {

    private String name;

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int doStartTag() throws JspException {
        String content = UseTemplateTag.getFragmentByName(pageContext.getRequest()).get(name);
        if (content != null) {
            try {
                pageContext.getOut().print(content);
            } catch (Exception ioe) {
                throw new JspException(ioe);
            }
        }
        return SKIP_BODY;
    }

    @Override
    public void doCatch(Throwable throwable) throws Throwable {
        throw throwable;
    }

    @Override
    public void doFinally() {
        this.name = null;
    }
}
